package test;

import java.io.InputStream;
import java.lang.reflect.Constructor;
import java.lang.reflect.Method;
import java.util.Scanner;

/**
 * @author zhu
 * @date 2024-03-26
 */
public class MainTest06 {
    public static void main(String[] args) throws Exception {
        Class<Scanner> clazz = Scanner.class;

        Constructor<Scanner> constructor = clazz.getConstructor(InputStream.class);
        Scanner scanner = constructor.newInstance(System.in);
        Method nextMethod = clazz.getMethod("next");
        System.out.println("输入一个合法的Email地址: ");
        String str = (String) nextMethod.invoke(scanner);

        Method sunstringMethod = String.class.getMethod("substring", int.class, int.class);
        Method indexOfMethod = String.class.getMethod("indexOf", String.class);

        int atIndex = (int) indexOfMethod.invoke(str,"@");
        String account = (String) sunstringMethod.invoke(str,0,atIndex);

        System.out.println("账户名为：" + account);
    }
}
